{% extends "shop/base.html" %}
{% load static %}

{% block title %}
    购物车
{% endblock %}

{% block content %}
    <h1>购物车</h1>
    <table class="cart">
        <thead>
        <tr>
            <th>图片</th>
            <th>名称</th>
            <th>数量</th>
            <th>操作</th>
            <th>单价</th>
            <th>总价</th>
        </tr>
        </thead>
        <tbody>
        {% for item in cart %}
            {% with product=item.product %}
                <tr>
                    <td><a href="{{ product.get_absolute_url }}">
                        <img src="
                                {% if product.image %}{{ product.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
                    </a></td>
                    <td>{{ product.name }}</td>
                    <td>
                        <form action="{% url "cart:cart_add" product.id %}" method="post">
                            {{ item.update_quantity_form.quantity }}
                            {{ item.update_quantity_form.update }}
                            <input type="submit" value="更新">
                            {% csrf_token %}
                        </form>
                    </td>
                    <td><a href="1{% url "cart:cart_remove" product.id %}">删除</a></td>
                    <td class="num">{{ item.price }}</td>
                    <td class="num">{{ item.total_price }}</td>
                </tr>
            {% endwith %}
        {% endfor %}
        <tr class="total">
            <td>总额</td>
            <td colspan="4"></td>
            <td class="num">¥ {{ cart.get_total_price }}</td>
        </tr>
        </tbody>
    </table>
    <p class="text-right">
        <a href="{% url "shop:product_list" %}" class="button light">继续购物</a>
        <a href="{% url "orders:order_create" %}" class="button">结账</a>
    </p>
{% endblock %}